/*Filename: LOADFILES.do
*Last updated: 2020-05-17

Description:
	This do-file loads the txt files (PSID downloads) into Stata datasets
	(into rawdata folder), using the PSID provided infile code. 
	The files include:
		-family files
		-cross-year individual file
		-parent identification file
		-marriage history file
		-childbirth & adoption file
		
*************************************************/
*Preamble
clear all
program drop _all
cap log close
set maxvar 10000


*************************************************
* Create globals for directories
//gl downloads "/users/kvosters/PSID/PSID_download"
//gl psidcode  "/users/kvosters/PSID/PSID_code"
//gl rawdata   "/users/kvosters/PSID/data/"


*************************************************
* Create program for loading text files (to Stata datasets)
program loadfile
	args root startyr endyr step suffix
	clear
	forv y=`startyr'(`step')`endyr' {
	  local UROOT=strupper("`root'")
	  local USUFFIX=strupper("`suffix'")
	  cd ${downloads}/`root'`y'`suffix'
	  do ${psidcode}/`UROOT'`y'`USUFFIX'.do
		cd $rawdata
		qui compress
		save `root'`y'`suffix'.dta, replace
		clear
		}
end

* Program for loading family income plus files (only difference is cd statement
program loadfile2
	args root startyr endyr step suffix
	clear
	forv y=`startyr'(`step')`endyr' {
	  cd ${downloads}/`root'
	  do ${psidcode}`root'`y'`suffix'.do
		cd $rawdata
		qui compress
		save `root'`y'`suffix'.dta, replace
		clear
		}
end

*************************************************
* Load text files using program "loadfile"

*Load family files
  loadfile fam 1968 1993 1 
  loadfile fam 1994 1997 1 er
  loadfile fam 1997 2019 2 er

*Load cross-year individual file
 loadfile ind 2019 2019 1 er

*Load parent identification file
 loadfile pid 19 19 1

*Load marriage history file
 loadfile mh 85 85 1 _19

*Load childbirth & adoption file
 loadfile cah 85 85 1 _19

* Loading wealth supplement files
 loadfile wlth 1984 1999 5 
 loadfile wlth 2001 2007 2

*** COULD ADD MANY OTHER FILES (e.g, Child development supplement, intergenerational transfers)

*** APPEARS THAT SOME FILES NO LONGER EXIST (NOW INCLUDED IN FAMILY FILES?)
 
/*  2017.06.15 -- it doesn't appear that the faminc files exist any longer???
* Loading family income files	
 loadfile2 faminc 1994 1996 1 	 
 loadfile2 faminc 1997 2001 2	
 // Note: The Family Income Plus 2003 and 2005 data are in the main family data files.

/* 2017.06.15 -- It doesn't appear that the hours files exist any longer??? */ 
** Loading hours/wages files
 loadfile hours 1994 1997 1 
 loadfile hours 1999 1999 1  
 // Note: 2001 file doesnt' work "no variables defined"
 // Note: Work Hours and Wages 2003 data are available in the main family data files.  

